With his new currency system, King Richard is now struggling to add, subtract, multiply, and divide amounts of money in his kingdom. Please write a program to help Richard with his mathematics.
Richard begins with a certain amount of money M. Possible operations include
ADD K add K to the current amount of money
SUB K subtract K from the current amount of money
MUL K multiply the current amount of money by K
DIV K divide the current amount of money by K
COB K change the base of the amount of money from base K to base 10.
0 < N < 100
0 < M < 1,000,000
For "COB": 2 < K < 10 {K an integer}
Assume that all operations are legal (e.g. no division by zero) and that each operation will result in a new whole number. Further assume that changing base will only be used once and, if used, will be the last operation in the set.
You will be OK if you store the net amount of money in a 32-bit integer.
Richard begins with a certain amount of money M. Possible operations include
ADD K add K to the current amount of money
SUB K subtract K from the current amount of money
MUL K multiply the current amount of money by K
DIV K divide the current amount of money by K
COB K change the base of the amount of money from base K to base 10.
0 < N < 100
0 < M < 1,000,000
For "COB": 2 < K < 10 {K an integer}
Assume that all operations are legal (e.g. no division by zero) and that each operation will result in a new whole number. Further assume that changing base will only be used once and, if used, will be the last operation in the set.
You will be OK if you store the net amount of money in a 32-bit integer.
Input Format
Line 1: N, the number of operations that Richard wants to performLine 2: M, the initial amount of money that Richard has
Lines 2..N+2: each individual operation of the form described in the problem statement
Sample Input
5
0
ADD 2
ADD 3
DIV 5
MUL 20
COB 4
Output Format Line 1: Print the new amount of money Richard has after the operations have successfully been performed.
Sample Output
8
You must be logged in to submit a solution.